package com.songdehuai.supermarket.supermarket.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.songdehuai.supermarket.R;
import com.songdehuai.supermarket.supermarket.entity.Shop;

import java.util.List;

public class ShopNameListAdapter extends BaseAdapter {

    private Context context;
    private List<Shop> shopList;

    public ShopNameListAdapter(Context context, List<Shop> shopList) {
        this.context = context;
        this.shopList = shopList;
    }

    @Override
    public int getCount() {
        return shopList.size();
    }

    @Override
    public Object getItem(int i) {
        return shopList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        if (null == viewHolder) {
            view = View.inflate(context, R.layout.item_shop_1, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.shopNameTv.setText(shopList.get(i).getShopname());
        return view;
    }

    class ViewHolder {
        TextView shopNameTv;

        public ViewHolder(View itemView) {
            shopNameTv = itemView.findViewById(R.id.item_title);
        }
    }
}
